import sys
from PyQt5.QtWidgets import QApplication
from src import MainWindow
import os

if __name__ == "__main__":
    app = QApplication(sys.argv)
    
    # 检查是否有命令行参数
    folder_path = None
    file_path = None
    
    if len(sys.argv) > 1:
        # 第一个参数是脚本路径，第二个参数可能是文件或文件夹路径
        potential_path = sys.argv[1]
        if os.path.exists(potential_path):
            if os.path.isfile(potential_path):
                # 如果是文件，保存文件路径
                file_path = potential_path
                # 同时设置文件夹路径为文件所在目录
                folder_path = os.path.dirname(potential_path)
            elif os.path.isdir(potential_path):
                # 如果是文件夹，保存文件夹路径
                folder_path = potential_path
    
    window = MainWindow(folder_path=folder_path, file_path=file_path)
    window.show()
    app.exec_()